﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DAL.LogicComponents;
using BAL.Entities;
using System.Data;

namespace BAL.Components
{
    public class clsUserBAL
    {
        #region --- User Login and Check Existed
        // Do user loging
        public static clsUser doUserLogin(clsUser obj)
        {
            try
            {
                return clsUserDAL.queryUserLogin(obj);
            }
            catch
            {
                throw;
            }
        }

        // Do check if user existed for register
        public static bool doUserExisted(clsUser obj)
        {
            try
            {
                return clsUserDAL.queryUserExisted(obj);
            }
            catch
            {
                throw;
            }
        }
        #endregion

        #region --- User Register
        // Do user register
        public static bool doUserRegister(clsUser obj)
        {
            try
            {
                return clsUserDAL.queryUserRegister(obj);
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region --- Update User Profile
        // Do user register
        public static bool doUpdateUserProfile(clsUser obj)
        {
            try
            {
                return clsUserDAL.queryUpdateUserProfile(obj);
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region --- Update User Avatar
        // Do user register
        public static bool doUpdateUserAvatar(clsUser obj)
        {
            try
            {
                return clsUserDAL.queryUpdateUserAvatar(obj);
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region --- Get User's City and Country
        // Do user register
        public static DataRow doGetUserCiCo(clsUser obj)
        {
            try
            {
                return clsCityDAL.queryGetUserCiCo(obj);
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region --- Get List All User
        // Do user register
        public static DataTable doGetAllUser()
        {
            try
            {
                return clsUserDAL.queryGetAllUser();
            }
            catch
            {
                throw;
            }
        }

        #endregion
        
        #region -- 
        public static DataTable doGetAllUserList(clsUser obj)
        {
            try
            {
                return clsUserDAL.queryGetUser(obj);
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region --- Update User's Cart
        // Do update user cart list
        public static bool doUpdateUserCart(clsUser obj)
        {
            try
            {
                return clsUserDAL.queryUpdateUserCartList(obj);
            }
            catch
            {
                throw;
            }
        }
        #endregion

        #region --- Update User's Favorite List
        // Do update user cart list
        public static bool doUpdateUserFavorite(clsUser obj)
        {
            try
            {
                return clsUserDAL.queryUpdateUserFavoriteList(obj);
            }
            catch
            {
                throw;
            }
        }
        #endregion

        #region --- Edit Password
        // Do Edit Password
        public static bool doEditPassword(clsUser obj)
        {
            try
            {
                return clsUserDAL.queryEditUserPassword(obj);
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region --- Get User Profile
        public static clsUser doGetUserProfile(clsUser obj)
        {
            try
            {
                DataRow dr = clsUserDAL.queryGetUserProfile(obj);
                obj.UserName = dr["colUserName"].ToString();
                obj.FirstName = dr["colFirstName"].ToString();
                obj.LastName = dr["colLastName"].ToString();
                obj.Address = dr["colAddress"].ToString();
                obj.Avatar = dr["colAvatar"].ToString();
                obj.BirthDay = DateTime.Parse(dr["colBirthday"].ToString());
                obj.Email = dr["colEmail"].ToString();
                obj.PhoneNumber = dr["colCellPhone"].ToString();
                obj.HomePhone = dr["colHomePhone"].ToString();
                obj.IdentityCard = dr["colIdentityCard"].ToString();
                obj.CityID = Convert.ToInt32(dr["colCityID"]);
                obj.CountryID = Convert.ToInt32(dr["CountryID"]);
                obj.Avatar = dr["colAvatar"].ToString(); 
                return obj;
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region --- get User by id
         public static DataTable doGetUserByID(clsUser obj)
        {
            try
            {
                return clsUserDAL.queryGetUser(obj);
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region --- get all User
         public static DataTable doGetAllUserList()
         {
             try
             {
                 return clsUserDAL.queryGetAllUser();
             }
             catch
             {
                 throw;
             }
         }

         #endregion
    }
}